package com.etaoking.commons;

import play.cache.Cache;
import play.mvc.Scope;
import play.mvc.Scope.Session;
import models.Users;

public class Contants {
	
	public static String url = "http://gw.api.taobao.com/router/rest";
	
	public static String appKey="12505673";
	
	public static String secret="d1ccdfbcf67c4533651f4ab1ae67b6d4";
	
	public static String user_key = "user_key_";
	
	public static String user_key_count = "user_key_count";
	
	public static class UserInfo{
		
		public static Users current(){
			Users users = Cache.get(user_key+Scope.Session.current().getId(), Users.class);
			put(users);
			return users;
		}
		
		public static void put(Users value){
			Cache.set(user_key+Scope.Session.current().getId(), value,"30mn");
			Cache.incr(user_key_count);
		}
		
		public static void remove(){
			Cache.delete(user_key+Scope.Session.current().getId());
			Cache.decr(user_key_count);
		}
		
		public static String getSessionKey(){
			return current().sessionKey;
		}
		
		public static int getCountOnLine(){
			return Cache.get(user_key_count,int.class);
		}
	}
}
